package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.IssuePolicy;
import cn.wolfcode.crm.domain.Policy;
import cn.wolfcode.crm.domain.Product;
import cn.wolfcode.crm.page.PageResult;
import cn.wolfcode.crm.query.IssuePolicyQueryObj;
import cn.wolfcode.crm.service.IIssuepolicyService;
import cn.wolfcode.crm.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("issuepolicy")
public class IssuepolicyController {

    @Autowired
    private IIssuepolicyService issuepolicyService;

    //收费查询界面定位
    @RequestMapping("")
    public String index() {
        //只负责跳转到menu.jsp页面即可
        return "feesearch";
    }
    //缴费处理界面定位
    @RequestMapping("view")
    public String view() {
        //只负责跳转到menu.jsp页面即可
        return "issuepolicy";
    }

    //产品信息
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(IssuePolicyQueryObj qo) {

        PageResult result = issuepolicyService.query(qo);
        return result;
    }

    @RequestMapping("remove")
    @ResponseBody
    public JsonResult remove(Long id) {
        JsonResult result = new JsonResult();
        try{
            issuepolicyService.deleteByPrimaryKey(id);
            result.setMessage("删除成功");
        }catch (Exception e){
            e.printStackTrace();
            result.mark("删除失败");
        }
        return result;
    }

    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(IssuePolicy issuePolicy) {
        JsonResult result = new JsonResult();
        try{
            issuepolicyService.update(issuePolicy);
            result.setMessage("缴费成功");
        }catch (Exception e){
            e.printStackTrace();
            result.mark("缴费失败");
        }
        return result;
    }

    @RequestMapping("selectProductBySn")
    @ResponseBody
    public List<Product>  selectProductBySn(String sn) {
        List<Product> products = issuepolicyService.selectProductBySn(sn);

        return products;
    }
}
